package edu.spec.chenli.Struts2;

import com.opensymphony.xwork2.ActionContext;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;

import static com.opensymphony.xwork2.Action.SUCCESS;
import static java.util.jar.Pack200.Packer.ERROR;

public class LoginAction implements Action {
    private  String username;
    private  String password;
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    public String execute()throws  Exception{
        ActionContext ac=ActionContext.getContext();
        Integer counter= (Integer) ac.getApplication().get("counter");
        if(counter==null){
            counter=1;
        }
        else {
            counter=counter+1;
        }
        ac.getApplication().put("counter",counter);
        ac.getSession().put("user",getUsername());
        if(getUsername().equals("abc")&& getPassword().equals("123")){
            ac.put("tip","服务器提示成功");
            return  SUCCESS;
        }
        ac.put("tip","服务器提示失败");
        return ERROR;
    }



    public Object getValue(String key) {
        return null;
    }

    public void putValue(String key, Object value) {

    }

    public void setEnabled(boolean b) {

    }

    public boolean isEnabled() {
        return false;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {

    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {

    }

    public void actionPerformed(ActionEvent e) {

    }
}
